﻿Cn_Regbus = {
    verify_business_name: function() {
        var name = $('name').value;
        Jes.doQueryList('vername_query_sql@bus', {paraObj: '{name:"' + name + '"}'}, function(data) {
            if (data[0].num > 0) {
                alert('此账号已注册');
            }
        });

    }
	//回车 激动按钮
	,onCenter : function(){
		alert(0);
		//	if(event.keyCode ==13){
		//		alert(1);
		//	}
	//	Cn_Regbus.reg(0);
	}
    ,initCKEditor: function() {
        var opts = {
//            toolbar:
            filebrowserImageBrowseUrl: '/browser/browse.php?type=Images',
            filebrowserImageUploadUrl: '/uploader/upload.php?type=Images'
        };
        CKEDITOR.replace('intro', opts);
    },

    initMap: function() {
        $('mapy').value = 30;
        $('mapx').value = 120;
        this.map = new google.maps.Map($('map_canvas'), {
            zoom: 15,
            center: new google.maps.LatLng(30, 120), // 初始中心点杭州
            mapTypeId: google.maps.MapTypeId.ROADMAP
        });
        this.geocoder = new google.maps.Geocoder();
    },

    locate: function() {
        var map = this.map;
        var area = $('area')[$('area').selectedIndex].text.trim().replaceAll('-', '');
        var city = $('city')[$('city').selectedIndex].text.trim().replaceAll('-', '');
        var address = area + city + $('address').value.trim();
//        console.log(address);
        this.geocoder.geocode({address: address}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                var latlng = results[0].geometry.location;
                $('mapy').value = latlng.lat();
                $('mapx').value = latlng.lng();
                map.setCenter(latlng);
                var marker = new google.maps.Marker({
                    title: $('name').value,
                    map: map,
                    position: latlng
                });
            }
        });
    }
    //初始化状态
    ,query :  function() {
        var userid = Jes.request('userid');
        var qrid = Jes.request('id');
        var email = Jes.request('email');
        Jes.doSaveTObject('cn.verify', {'isSess':0,param:{'id':qrid}}, function(result) {
            if (result == 1) {
				window.location.href="http://www.cuniao.com/cuniao";
            } else {
                $('userid').value = userid;
                $('email').value = email;
                Jes.doSync(function() {//异步函数
                    Jes.Select.area();
                    Jes.Select.city();
                });
            }
        });	

    }
    //商家注册按钮
    ,reg : function(isBus) {
        var email = $('email').value;
        Jes.doQueryList('verify_query_sql@bus', {isSess:0,paraObj:'{email:"' + email + '"}',isLoad:false}, function(data) {
            if (data[0].num > 0) {
                alert("该邮箱已经注册，请直接登录。");
                window.location.href = "http://www.cuniao.com/cuniao/";
            } else {
                Jes.query('reverify_query_sql@bus', {paraObj:'{isSess:0,email:"' + email + '"}',isLoad:false}, function(data) {
                    if (data[0].num > 0) {
                        alert("该邮箱已经注册，请到邮箱激活账号。");
                        var eService = Cn_Regbus.getmailservice(email);
                        //window.location.href = eService;//跳转到邮箱
                    } else {
                        var password = $('password').value;
                        var repassword = $('repassword').value;
                        if (password == repassword) {
                            Jes.doSaveTObject('CnUser', {isSess:0,isLoad:false}, function(data) {
                                var eService = Cn_Regbus.getmailservice(email);
                                Jes.html('content', '<h1>查收确认信</h1><div class="grid-16-8 clearfix"><div class="article">' +
                                    '<p class="pl">确认信已经发到你的邮箱 <span id="email">' + email + '</span> ，你需要点击邮件中的确认链接来完成注册。</p>' +
                                    '<h2>没有收到确认信怎么办？······</h2><ol><li>检查一下上面Email地址是否正确，错了就<a href="/accounts/register">重新注册</a>一次吧:)</li>' +
                                    '<li>看看是否在邮箱的垃圾箱里</li><li>稍等几分钟，若仍旧没收到确认信，让簇鸟<a href="" id="a_resend">重发一封</a></ol>');
                            });
                        } else {
                            alert("密码输入不一致");
                        }
                    }
                });

            }
        });
    }
    //邮箱服务器地址
    ,getmailservice : function(email) {
        var i = email.indexOf('@');
        var eService = 'http://mail.' + email.substring(i + 1);
        return eService;
    }
    //保存商家信息
    ,savebus : function() {
        var intro = CKEDITOR.instances.intro.getData();
        $('intro').value = intro;
//      console.log(intro);
//		alert($('address').value);
//		alert($('city').value);
        Jes.doSaveTObject('CnBusiness', '', function(data) {
            if (data == '') {
                alert('注册失败');
            } else {
                window.location.href = 'http://www.cuniao.com/cuniao/cuniao/bus/busconfirm.html?busid='+data;
                alert('注册成功');
            }
        });
    }
	
}